import pandas as pd
import matplotlib.pyplot as plt
import requests

# 高德地图API Key（请替换为你的有效API Key）
api_key = '2074e3830cf12c789ed409e1517eed6d'

# 定义全局颜色列表和透明度
colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k']  # 颜色列表：蓝、绿、红、青、洋红、黄、黑
alpha_value = 0.2  # 透明度值

def get_coordinates(api_key, address):
    # 使用高德地图API获取坐标的函数（如果需要）
    # 此处省略API调用细节，返回经纬度坐标
    pass

def read_excel(file_path):
    # 读取Excel文件的函数
    return pd.read_excel(file_path)

def process_building_data(building_name, file_path, routes):
    data = read_excel(file_path)
    for index, row in data.iterrows():
        start_point = tuple(map(float, row['起点坐标'].split(',')))
        dest_point = tuple(map(float, row['目的地坐标'].split(',')))
        # 检查字典中是否已经有该建筑的键，如果没有，则创建一个空列表
        if building_name not in routes:
            routes[building_name] = []
        # 添加路线到对应建筑的列表中
        routes[building_name].append((start_point, dest_point))

def plot_routes(routes):
    fig, ax = plt.subplots()
    color_index = 0  # 用于选择颜色的索引

    for building_name, routes in routes.items():
        color = colors[color_index % len(colors)]
        color_index += 1

        for start_point, dest_point in routes:
            ax.plot([start_point[0], dest_point[0]], [start_point[1], dest_point[1]],
                    color=color, linewidth=0.5, alpha=alpha_value, label=f'{building_name} Routes')

    # 添加图例、坐标轴标签和标题
    ax.legend(loc='upper left', bbox_to_anchor=(1, 1))
    plt.xlabel('Longitude')
    plt.ylabel('Latitude')
    plt.title('Routes from Start Points to Destinations')
    plt.axis('equal')  # 保持纵横坐标轴比例相同
    plt.show()

def main():
    # 定义起点和文件路径
    buildings = {
        "中诚大厦": "E:\Program Files\Pythonproject\pythonProject1\中诚大厦_行车方案数据.xlsx",
        "武银大厦": "E:\Program Files\Pythonproject\pythonProject1\武银大厦_行车方案数据.xlsx",
        "良友大厦": "E:\Program Files\Pythonproject\pythonProject1\良友大厦_行车方案数据.xlsx"
    }

    routes = {building: [] for building in buildings}  # 初始化路线字典

    # 处理每个大厦的数据
    for building_name, file_path in buildings.items():
        print(f"Processing {building_name} data...")
        process_building_data(building_name, file_path, routes)
    # 绘制路径图
    plot_routes(routes)

if __name__ == "__main__":
    main()